import glob
import os
from tensorflow.python.framework.ops import convert_to_tensor
import numpy as np
from tensorflow.python.framework import dtypes
import tensorflow as tf
from tensorflow.contrib.data import Dataset
import tensorflow.contrib.eager as tfe

learning_rate = 1e-4
num_epochs = 100  # 代的个数
batch_size = 1024
dropout_rate = 0.5
num_classes = 2  # 类别标签
train_layers = ['fc8', 'fc7', 'fc6']
display_step = 20

filewriter_path = "tmp/tensorboard"  # 存储tensorboard文件
checkpoint_path = "tmp/checkpoints"  # 训练好的模型和参数存放目录

if not os.path.isdir(checkpoint_path):
    os.mkdir(checkpoint_path)

train_image_path = 'F:\\001-python\\train_1\\'  # 指定训练集数据路径（根据实际情况指定训练数据集的路径）
test_image_cat_path = 'F:\\001-python\\test\\test_cat\\'  # 指定测试集数据路径（根据实际情况指定测试数据集的路径）
test_image_dog_path = 'F:\\001-python\\test\\test_dog\\'  # 指定测试集数据路径（根据实际情况指定测试数据集的路径）

label_path = []
test_label = []

# 打开训练数据集目录，读取全部图片，生成图片路径列表
image_path = np.array(glob.glob(train_image_path + 'cat.*.jpg')).tolist()
image_path_dog = np.array(glob.glob(train_image_path + 'dog.*.jpg')).tolist()
image_path[len(image_path):len(image_path)] = image_path_dog
for i in range(len(image_path)):
    if 'dog' in image_path[i]:
        label_path.append(1)
    else:
        label_path.append(0)

# a=np.array([0,1,2,3,4]).tolist()
# b=np.array([5,6,7,8,9]).tolist()
# # 列表合并的方法
# a[5:5]=b
# print(a)

# 打开测试数据集目录，读取全部图片，生成图片路径列表
test_image = np.array(glob.glob(test_image_cat_path + '*.jpg')).tolist()
test_image_path_dog = np.array(glob.glob(test_image_dog_path + '*.jpg')).tolist()
print(test_image)
test_image[len(test_image):len(test_image)] = test_image_path_dog
print(test_image)
for i in range(len(test_image)):
    if i < 1500:
        test_label.append(0)
    else:
        test_label.append(1)

img_paths = convert_to_tensor(test_image, dtype=dtypes.string)
labels = convert_to_tensor(test_label, dtype=dtypes.int32)
# http://blog.csdn.net/kwame211/article/details/78579035
data = Dataset.from_tensor_slices((img_paths, labels))
iterator = data.make_one_shot_iterator()
one_element = iterator.get_next()

with tf.Session() as sess:

    # sess.run(tf.global_variables_initializer())
    try:
        while True:
            print(sess.run(one_element))
    except tf.errors.OutOfRangeError:
        print("end!")
    # print(img_paths.eval())
    # print(labels.eval())
    # print(data)